jQuery(function(){
	
	// 引入客户信息弹窗
	jQuery('#queryCustomer').on("click", function() {
		showCustomer();//显示客户信息
	});
	jQuery('#pull-customer-in').on('click',function(){
		var selects=getSelect("#query-customer-table",1);
		if(selects.length>1){
	   		  message("只能引入一条客户");
	   	   }
	   	   else if(selects.length==0){
	   		   message("没有选中客户");
	   	   }else if(selects.length==1){
	   		  jQuery("#ownerUnit").val(selects[0].customerName);
	   		  jQuery("#customerId").val(selects[0].id);
		   	  jQuery("#query-Customer-Modal").modal('hide');
	   	   }
		
	});
	
    ///保存投标
	jQuery('.saveBidBtn').on('click',function(){
			if (jQuery("#bidForm") && !jQuery("#bidForm").Validform({
				tiptype : 3,
				showAllError : true
			}).check(false)) {
				return;
			};
			savebid(1);	
	})
	////保存投标的function
	function savebid(re,fileType){
		var costSum = jQuery('#costSum').val();
		var sum = jQuery('#sum').val();
		var costomerId = jQuery('#customerId').val();
		var quoteId=jQuery('#quoteId').val();
		var foreignId=jQuery('#foreignId').val();
		var id=jQuery("#bidId").val();
		var bidcreateTime=jQuery("#createTime").val();
		var createTime=new Date(bidcreateTime).getTime() ;
		var name=jQuery("#name").val();
		var bidUnit=jQuery("#bidUnit").val();
		var ownerUnit=jQuery('#ownerUnit').val();
		var launcher=jQuery('#launcher').val();
		var launch=jQuery('#launch').val();
		var type=jQuery('#type').val();
		var projectType=jQuery('#projectType').val();
		var cashType=jQuery('#cashType').val();
		var cash=jQuery('#cash').val();
		var bidDate=jQuery('#bidDate').val();
		var terms=jQuery('#terms').val();
		var memo=jQuery('#memo').val();
		var isUnder100=jQuery('#isUnder100').val();
		var isNew=jQuery('#isNew').val();
		var isForeign=jQuery('#isForeign').val();
		var quoteType=jQuery('#quoteType').val();
		var url=window.rootPath+"/ui/bid/save";
		if(id==''){
			   var d = {
					"costSum" : costSum,
					"sum" : sum,
					"customerId": costomerId,
	      			"name": name,
	   	            "bidUnit": bidUnit,
	   	            "ownerUnit": ownerUnit,
	   	            "launcher": launcher,
	   	            "launch": launch,
	   	            "type": type,
	   	            "projectType": projectType,
	   	            "cashType": cashType,
	   	            "cash": cash,
	   	            "bidDate": bidDate,
	   	            "quote":{
	   	            	"id":quoteId
	   	            },
	   	            "quoteForeign":{
	   	            	"id":foreignId
	   	            },
	   	            "terms":terms,
	   	            "memo":memo,
	   	            "isUnder100":isUnder100,
	   	            "isNew":isNew,
	   	            "isForeign":isForeign,
	   	            "quoteType":quoteType
	   	        };
	      }else{
	    	  var d = {
	    			  "costSum" : costSum,
						"sum" : sum,
	    			  "customerId": costomerId,
	    			    "id":id,
	    			    "createTime":createTime,
	        			"name": name,
	     	            "bidUnit": bidUnit,
	     	            "ownerUnit": ownerUnit,
	     	            "launcher": launcher,
	     	            "launch": launch,
	     	            "type": type,
	     	            "projectType": projectType,
	     	            "cashType": cashType,
	     	            "cash": cash,
	     	            "bidDate": bidDate,
	     	            "quote":{
		   	            	"id":quoteId
		   	            },
		   	            "quoteForeign":{
		   	            	"id":foreignId
		   	            },
		   	            "terms":terms,
		   	            "memo":memo,
		   	            "isUnder100":isUnder100,
		   	            "isNew":isNew,
		   	            "isForeign":isForeign,
		   	            "quoteType":quoteType
	     	        };
	      }
		jQuery(".btn").attr("disabled", true);
		  jQuery.ajax({
	          type: 'post',
	          url: encodeURI(url),
	          data: JSON.stringify(d),
	          dataType: 'json',
	          contentType: 'application/json;charset=utf-8',
	          success: function (data) {
	        	  jQuery(".btn").attr("disabled", false);
	        	  if(re==1){
	        		  window.location = window.rootPath+"/ui/bid"; 
	        	  }
	        	  else if(re==2){
	        		  var bidId=data.bidId;
	        		  jQuery('#bidId').val(bidId);
	        		  var time=moment(data.createTime).format("YYYY-MM-DD HH:mm:ss")
	            	  jQuery("#createTime").val(time);
	        		  fileUpload(bidId,fileType,null,'techNum');
	        	  }  
	          }
    	  	});
	}
	
	jQuery(".btnUpload1").on("click", function() {
		if (jQuery("#bidForm") && !jQuery("#bidForm").Validform({
			tiptype : 3,
			showAllError : true
			}).check(false)) {
			return;
		};
		savebid(2,'保函')
	});
	jQuery(".btnList1").on("click", function() {
        var bidId=jQuery('#bidId').val();
		filedown(bidId,'保函','1');
	});
	
	jQuery(".btnUpload2").on("click", function() {
		if (jQuery("#bidForm") && !jQuery("#bidForm").Validform({
			tiptype : 3,
			showAllError : true
			}).check(false)) {
			return;
		};
		savebid(2,'技术方案')
	});
	jQuery(".btnList2").on("click", function() {
        var bidId=jQuery('#bidId').val();
		filedown(bidId,'技术方案','1');
	});
	
	jQuery(".btnListSee").on("click", function() {
        var bidId=jQuery('#bidId').val();
		filedown(bidId,'技术方案','0');
	});
     ////获附件数量
	var bidId=jQuery("#bidId").val();
	var numId='techNum';
	if(bidId!=''){
		showANum(bidId,'技术方案',numId);
	}
	
	
	
	
	
	
})

